package app.netmorphgui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class Icons {

	public static ImageIcon renderWarnings(int n) throws IOException
	{
		BufferedImage icon = ImageIO.read(new File("icons/warning-icon.png"));		
		BufferedImage buf = new BufferedImage(icon.getWidth(), icon.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
		Graphics2D g2 = (Graphics2D) buf.getGraphics();
		g2.drawImage(icon, 0, 0, null);
		
		String txt = "" + n;
		Font f = new Font("Verdana", Font.BOLD, 8);
		g2.setFont(f);
		Rectangle2D rect = f.getStringBounds(txt, g2.getFontRenderContext());
		int x = icon.getWidth()*1/4;
		int y = icon.getHeight();
		g2.setBackground(new Color(200, 200, 200));
		g2.fillRect(x-2, (int) (y-2-rect.getHeight()), (int) (4+rect.getWidth()), (int)(4+rect.getHeight()));
		g2.setColor(Color.black);
		g2.drawString(""+n, x, y-4);
		ImageIcon icon2 = new ImageIcon(buf);
		return icon2;
	}
}
